package cn.qidd.keep.manage.model.system;

import cn.qidd.keep.domain.document.QUser;
import cn.qidd.keep.domain.model.BaseSearch;
import com.querydsl.core.BooleanBuilder;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.apache.commons.lang.StringUtils;

import javax.validation.constraints.NotBlank;

@Data
public class UserSearchParams extends BaseSearch {
    @ApiModelProperty(value = "用户名")
    private String userName;
    @ApiModelProperty("用户真名")
    private String realName;
    @ApiModelProperty("用户手机号")
    private String tel;
    @NotBlank
    @ApiModelProperty(value = "部门Code", required = true)
    private String deptCode;

    @Override
    public BooleanBuilder generateSearchCondition() {
        BooleanBuilder booleanBuilder = new BooleanBuilder();
        QUser qMongoUser = QUser.user;
        if (StringUtils.isNotBlank(this.userName)) {
            booleanBuilder.and(qMongoUser.userName.like("%"+this.userName+"%"));
        }
        if (StringUtils.isNotBlank(this.realName)) {
            booleanBuilder.and(qMongoUser.realName.like("%"+this.userName+"%"));
        }
        if (StringUtils.isNotBlank(this.tel)) {
            booleanBuilder.and(qMongoUser.tel.like("%"+this.tel+"%"));
        }
        if (StringUtils.isNotBlank(this.deptCode)) {
            booleanBuilder.and(qMongoUser.department.deptCode.startsWith(deptCode));
        }
        return booleanBuilder;
    }
}
